class Solution {
public:
    bool checkInclusion(string s1, string s2) {
        int m = s1.size();
        int n = s2.size();
        vector<int> hash1(26),hash2(26);
        
        if(n < m) return false;
        
        for(int i = 0;i < m;i++){
            hash1[s1[i]-'a']++;
            hash2[s2[i]-'a']++;
        }
        
        int l = 0;
        int r = m;
        
        if(hash1 == hash2){
            return true;
        }
            
        while(r < n){
            hash2[s2[r]-'a']++;
            hash2[s2[l]-'a']--;
            r++;
            l++;
            if(hash2 == hash1){
                return true;
            }
        }
        return false;
    }
};
